"use strict";
cc._RF.push(module, 'f0702XYMYRL0rzB7vfOFYsb', 'CodeHelper');
// script/original/Standar/Utils/CodeHelper.js

"use strict";

window.CodeHelper = {
  /**
   * 生成二维码
   * @param {cc.Graphics} graph 二维码绘制与CC.Graphis
   * @param {string} content 二维码的文本 
   */
  creatQRCode: function creatQRCode(graph, content) {
    var qrcode = new QRCode(-1, QRErrorCorrectLevel.H);
    qrcode.addData(content);
    qrcode.make(); // 计算宽高

    var tileW = graph.node.width / qrcode.getModuleCount();
    var tileH = graph.node.height / qrcode.getModuleCount(); // 绘制二维码

    for (var row = 0; row < qrcode.getModuleCount(); row++) {
      for (var col = 0; col < qrcode.getModuleCount(); col++) {
        if (qrcode.isDark(row, col)) {
          var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW);
          var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW);
          graph.rect(Math.round(col * tileW) - graph.node.width / 2, Math.round(row * tileH) - graph.node.height / 2, w, h);
          graph.fill();
        }
      }
    }
  },

  /**
   * 生成条形码
   * @param {string} content 条形码内容
   * @param {cc.SpriteFrame} callBack 生成的SpriteFrame
   */
  creatBarCode: function creatBarCode(content, callBack) {
    //先使用Html端创建Img，使用插件生成由Base64编码的条形码
    var barcode = document.getElementById("barcode");

    if (barcode == null) {
      barcode = document.createElement("img");
      barcode.id = "barcode";
      barcode.style.height = "0px";
      barcode.style.display = "block";
      barcode.style.overflow = "hidden";
      document.body.insertBefore(barcode, document.body.firstChild);
    }

    var options = {
      format: "CODE128",
      displayValue: true,
      fontSize: 18,
      height: 50,
      textMargin: 5,
      font: "Sabs-serif"
    };
    JsBarcode(barcode, content, options); //生成条形码
    //获取Base64编码，转化成Sprite

    ImageHelper.base64ToSpriteFrame(barcode.src, callBack);
  }
};

cc._RF.pop();